package com.finance.cooperate.dao.repository.secondary;

import com.finance.cooperate.dao.entity.secondary.ModelInfo;
import com.finance.cooperate.dao.support.jpa.BaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @InterfaceName ModelInfoRepository
 * @Description 模型仓库
 * @Author shen
 * @Date 2023/8/6 21:48
 * @Modify ...
 */
@Repository
public interface ModelInfoRepository extends BaseRepository<ModelInfo, Long> {

    /**
     * @Author shen
     * @Description 查询同一分离器下的模型
     * @Date 6:47 下午 2021/2/23
     * @Param [diversionId]
     * @return java.util.List<cm.finance.crm.dao.entity.secondary.ModelInfo>
     **/
    @Query(value = "SELECT * FROM rc_model_info m WHERE m.diversion_id = ?1 AND m.status = 1 AND m.weight > 0", nativeQuery = true)
    List<ModelInfo> getDiversionId(Long diversionId);


    /**
     * @Author shen
     * @Description 根据项目查询所有model
     * @Date 1:29 下午 2021/3/5
     * @Param [project]
     * @return java.util.List<cm.finance.crm.dao.entity.secondary.ModelInfo>
     **/
    @Query(value = "SELECT m.* FROM rc_model_info m LEFT JOIN rc_diversion_info d ON m.diversion_id = d.id WHERE d.project = ?1 AND m.is_deleted = 0 ORDER BY m.updated DESC",
            countQuery = "SELECT Count(*) FROM rc_model_info m LEFT JOIN rc_diversion_info d ON m.diversion_id = d.id WHERE d.project = ?1 AND m.is_deleted = 0",
            nativeQuery = true)
    Page<ModelInfo> getAllModelByProject(String project, Pageable pageable);

}
